package com.liang.demo1.service;


import com.liang.demo1.anno.TargetDataSource;
import com.liang.demo1.domain.Account;
import com.liang.demo1.repository.AccountRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;

@Service
public class AccountService {


    @Resource
    AccountRepository repository;


    @TargetDataSource(dataSource = "writeDruidDataSource")
    public void save(){
        Account account = new Account();
        account.setName("liang");
        account.setBalance(new BigDecimal(1000));
        account.setTime(new Date());
        System.out.println(account);
        repository.save(account);
    }

    public void save(Account account){
        repository.save(account);
    }

    @TargetDataSource(dataSource = "readDruidDataSource")
    public Account getAccount(String id) {
        return repository.getById(id);
    }

}
